package com.cuit.filter;


import com.cuit.constants.Constants;
import com.cuit.extension.Activate;
import com.cuit.remoting.dto.RpcRequest;
import com.cuit.remoting.dto.RpcResponse;
import lombok.extern.slf4j.Slf4j;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.concurrent.CompletableFuture;

@Activate(group = Constants.CONSUMER, order = 1)
@Slf4j
public class MonitorFilter implements Filter {
    @Override
    public void doFilter(FilterContext fIlterContext) throws Exception {
        RpcRequest rpcRequest = fIlterContext.getRpcRequest();
        LocalDateTime start = LocalDateTime.now();
        log.info("请求id:{},调用服务名字:{},进入时间：[{}]"
                ,rpcRequest.getRequestId(), rpcRequest.getRpcServiceName(), start);
        fIlterContext.getFilterChain().doFilter(fIlterContext);
        LocalDateTime end = LocalDateTime.now();
        log.info("请求id:{},调用服务名字:{},结束时间：[{}]"
                ,rpcRequest.getRequestId(), rpcRequest.getRpcServiceName(), end);
        log.info("调用服务名字:{}------》》耗时：[{}]ms"
                , rpcRequest.getRpcServiceName(),Duration.between(start, end).toMillis());
    }
}
